package com.example.take_out_dish.handle;


import com.example.take_out_dish.common.Result;
import com.example.take_out_dish.exceptions.BusinessException;
import com.example.take_out_dish.exceptions.enumetation.ResponseEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wuyunbin
 */
@RestControllerAdvice
public class BaseExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result<Object> exceptionHandler(Exception e) {
        e.printStackTrace();
        return Result.error(ResponseEnum.UNKNOWN_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public Result<Object> businessExceptionHandler(BusinessException e) {
        return Result.error(e.getResponse());
    }
}
